home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / misc / unix / tracker_4_3.lzh / tracker / dump_song.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-13  |  4.6 KB  |  204 lines

  1. /* dump_song.c 
  2.     vi:se ts=3 sw=3:
  3.  */
  4.  
  5. /* $Id: dump_song.c,v 4.1 1994/01/12 16:11:07 espie Exp espie $
  6.  * $Log: dump_song.c,v $
  7.  * Revision 4.1  1994/01/12  16:11:07  espie
  8.  * Last minute changes.
  9.  *
  10.  * Revision 4.0  1994/01/11  17:46:01  espie
  11.  * Use virtual windows.
  12.  *
  13.  * Revision 1.8  1994/01/09  17:36:22  Espie
  14.  * Generalized open.c.
  15.  *
  16.  * Revision 1.7  1994/01/08  03:55:43  Espie
  17.  * No more call to run_in_fg(), use begin_info result instead.
  18.  *
  19.  * Revision 1.6  1994/01/06  22:32:42  Espie
  20.  * Added instrument name as shown per display.c.
  21.  *
  22.  * Revision 1.5  1994/01/05  16:10:49  Espie
  23.  * *** empty log message ***
  24.  *
  25.  * Revision 1.4  1994/01/05  14:54:09  Espie
  26.  * *** empty log message ***
  27.  *
  28.  * Revision 1.3  1994/01/05  13:50:43  Espie
  29.  * Cosmetic change.
  30.  *
  31.  * Revision 1.2  1993/12/28  13:54:44  Espie
  32.  * Use info facility.
  33.  *
  34.  * Revision 1.1  1993/12/26  00:55:53  Espie
  35.  * Initial revision
  36.  *
  37.  * Revision 3.7  1993/11/17  15:31:16  espie
  38.  * *** empty log message ***
  39.  *
  40.  * Revision 3.6  1993/11/11  20:00:03  espie
  41.  * Amiga support.
  42.  *
  43.  * Revision 3.5  1993/04/28  20:13:13  espie
  44.  * Very small bug with volume (Lawrence).
  45.  *
  46.  * Revision 3.4  1993/04/25  14:08:15  espie
  47.  * Added finetune display.
  48.  *
  49.  * Revision 3.3  1993/01/15  14:00:28  espie
  50.  * Added bg/fg test.
  51.  *
  52.  * Revision 3.1  1992/11/19  20:44:47  espie
  53.  * Protracker commands.
  54.  *
  55.  * Revision 3.0  1992/11/18  16:08:05  espie
  56.  * New release.
  57.  */
  58.  
  59. #include "defs.h"
  60.  
  61. #ifdef MALLOC_NOT_IN_STDLIB
  62. #include <malloc.h>
  63. #else
  64. #include <stdlib.h>
  65. #endif
  66. #include <stdio.h>
  67. #include <string.h>
  68. #include <ctype.h>
  69.  
  70. #include "song.h"
  71. #include "extern.h"
  72. #include "channel.h"
  73.  
  74. ID("$Id: dump_song.c,v 4.1 1994/01/12 16:11:07 espie Exp espie $")
  75.  
  76. LOCAL void *handle = 0;
  77. LOCAL char buffer[80];
  78. extern char instname[];
  79.  
  80. /***
  81.  *
  82.  *  dump_block/dump_song:
  83.  *  shows most of the readable info
  84.  *  concerning a module on the screen.
  85.  *
  86.  ***/
  87.  
  88. LOCAL void dump_block(b)
  89. struct block *b;
  90.    {
  91.    int i, j;
  92.  
  93.    for (i = 0; i < BLOCK_LENGTH; i++)
  94.       {
  95.       for (j = 0; j < NUMBER_TRACKS; j++)
  96.          {
  97.          sprintf(buffer,"%8d%5d%2d%4d", b->e[j][i].sample_number,
  98.             b->e[j][i].pitch, b->e[j][i].effect,
  99.             b->e[j][i].parameters);
  100.          infos(handle, buffer);
  101.          }
  102.       info(handle, "");
  103.       }
  104.    }
  105.  
  106. /* make_readable(s):
  107.  * transform s into a really readable string */
  108.  
  109. LOCAL void make_readable(s)
  110. char *s;
  111.    {
  112.    char *t, *orig;
  113.  
  114.    if (!s)
  115.       return;
  116.  
  117.    orig = s;
  118.    t = s;
  119.  
  120.       /* get rid of the st-xx: junk */
  121.    if (strncmp(s, "st-", 3) == 0 || strncmp(s, "ST-", 3) == 0)
  122.       {
  123.       if (isdigit(s[3]) && isdigit(s[4]) && s[5] == ':')
  124.          s += 6;
  125.       }
  126.    while (*s)
  127.       {
  128.       if (isprint(*s))
  129.          *t++ = *s;
  130.       s++;
  131.       }
  132.    *t = '\0';
  133.    while (t != orig && isspace(t[-1]))
  134.       *--t = '\0';
  135.    }
  136.  
  137. void dump_song(song)
  138. struct song *song;
  139.    {
  140.    int i, j;
  141.    int maxlen;
  142.    static char dummy[1];
  143.  
  144.    
  145.    handle = begin_info(song->title);
  146.    if (!handle)
  147.       return;
  148.  
  149.    dummy[0] = '\0';
  150.    maxlen = 0;
  151.    for (i = 1; i < NUMBER_SAMPLES; i++)
  152.       {
  153.       if (!song->samples[i].name)
  154.          song->samples[i].name = dummy;
  155.       make_readable(song->samples[i].name);
  156.       if (maxlen < strlen(song->samples[i].name))
  157.          maxlen = strlen(song->samples[i].name);
  158.       }
  159.    for (i = 1; i < NUMBER_SAMPLES; i++)
  160.       {
  161.       if (song->samples[i].start || strlen(song->samples[i].name) > 2)
  162.          {
  163.          char s[3];
  164.          
  165.          s[0] = instname[i];
  166.          s[1] = ' ';
  167.          s[2] = 0;
  168.          infos(handle, s);
  169.          infos(handle, song->samples[i].name);
  170.          for (j = strlen(song->samples[i].name); j < maxlen + 2; j++)
  171.             infos(handle, " ");
  172.          if (song->samples[i].start)
  173.             {
  174.             sprintf(buffer, "%5d", song->samples[i].length);
  175.             infos(handle, buffer);
  176.             if (song->samples[i].rp_length > 2)
  177.                {
  178.                sprintf(buffer, "(%5d %5d)", 
  179.                   song->samples[i].rp_offset, 
  180.                   song->samples[i].rp_length);
  181.                infos(handle, buffer);
  182.                }
  183.             else
  184.                infos(handle, "             ");
  185.             if (song->samples[i].volume != MAX_VOLUME)
  186.                {
  187.                sprintf(buffer, "%3d", song->samples[i].volume);
  188.                infos(handle, buffer);
  189.                }
  190.             else 
  191.                infos(handle, "   ");
  192.             if (song->samples[i].finetune)
  193.                {
  194.                sprintf(buffer, "%3d", song->samples[i].finetune);
  195.                infos(handle, buffer);
  196.                }
  197.             }
  198.          info(handle, "");
  199.          }
  200.       }
  201.    end_info(handle);
  202.    handle = 0;
  203.    }
  204.